//
//  UIButton+ActionBlock.m
//  BaseToolsKit
//
//  Created by zyming on 2022/9/16.
//

#import "UIButton+ActionBlock.h"
#import <Foundation/Foundation.h>
#import <objc/runtime.h>

@implementation UIButton (ActionBlock)
static char overviewKey;

- (void)addAcionBlock:(VoidBlock)action{

    objc_setAssociatedObject(self, &overviewKey, action,OBJC_ASSOCIATION_COPY_NONATOMIC);

    [self addTarget:self action:@selector(callActionBlock:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)callActionBlock:(UIButton *)sender {

    VoidBlock block = (VoidBlock)objc_getAssociatedObject(self, &overviewKey);

    if (block) {
        block(sender);
    }
}
@end
